<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateOrdersTable extends Migration
{
    public function up()
    {
        Schema::create('orders', function (Blueprint $table) {
            $table->id();
	        $table->unsignedBigInteger('user_id')->index()->default(0);
	        $table->unsignedBigInteger('seckill_id')->index()->default(0);
	        $table->unsignedBigInteger('blind_box_order_id')->index()->default(0);
	        $table->unsignedBigInteger('user_coupon_id')->index()->default(0);
	        $table->string('number', 30)->unique()->comment('number of this order');
	        $table->decimal('total_amount', 10, 2)->default(0);
	        $table->decimal('total_profit', 10, 2)->default(0);

	        $table->string('province')->nullable();
	        $table->string('city')->nullable();
	        $table->string('district')->nullable();
	        $table->text('address')->comment('json field: includes address,zip,contats');

	        $table->dateTime('paid_at')->nullable()->index();
	        $table->string('paid_method')->nullable();
	        $table->string('paid_number')->nullable()->index();

	        $table->string('delivery_status')->default('pending');
	        $table->text('delivery_data')->nullable()->comment('data about delivery');

	        $table->dateTime('closed_at')->nullable()->index();
	        $table->dateTime('cancelled_at')->nullable()->index();
	        $table->dateTime('received_at')->nullable()->index();

	        $table->text('adapay_data')->nullable()->comment('adapay pay_info');
	        $table->text('extra_data')->nullable()->comment('extra data');
	        $table->text('drink_data')->nullable()->comment('drink data');

	        $table->boolean('has_refund')->default(false)->comment('if this order items has any refund');
	        $table->boolean('has_commented')->default(false);

	        $table->boolean('is_send')->default(false);
	        $table->boolean('is_return')->default(false);
	        $table->boolean('is_seckill')->default(false);
	        $table->string('cache_id')->default('');

	        $table->softDeletes();
            $table->timestamps();

            $table->index(['created_at']);
        });
    }

    public function down()
    {
        Schema::dropIfExists('orders');
    }
}
